package grafica;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import net.Client;

public class NetFrame extends JFrame {
	NetPanel np;
	ChatPanel cp;
	JPanel pannelloPrincipale;
	Client client;
	JPanel vuoto = new JPanel();
	ConnectPanel connectPanel;
	

	public NetFrame(String host,int port,String user) {
		super();		
		//connectPanel = new ConnectPanel(this);
		cp = new ChatPanel(null);
		pannelloPrincipale = new JPanel();
		pannelloPrincipale.setLayout(new BorderLayout());
		pannelloPrincipale.add(vuoto,BorderLayout.CENTER);
		//pannelloPrincipale.add(connectPanel,BorderLayout.NORTH);
		pannelloPrincipale.add(cp,BorderLayout.SOUTH);
		
		this.setSize(800,750);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//this.getContentPane().add(np);
		this.getContentPane().add(pannelloPrincipale);
		this.setTitle("Unicalman");
		this.setResizable(false);
		connetti(host,port,user);
	}
	
	public void connetti(String host,int port,String user) {
		client = new Client(host,port,user);
		client.setTextArea(cp.getText());
		cp.setOut(client.getOut());
		pannelloPrincipale.remove(vuoto);
		//pannelloPrincipale.remove(connectPanel);
		np = new NetPanel(client);	
		pannelloPrincipale.add(np,BorderLayout.CENTER);
		pannelloPrincipale.updateUI();	
		np.requestFocus();
		this.setTitle("Unicalman --- "+user);
	}
	
	public static void main(String[] args) {
		NetFrame nt = new NetFrame("localhost",4444,"ciccio");
		nt.setVisible(true);
	}

}
